﻿//-----------------------------------------------------------------------
// <copyright file="UserNamePasswordViewModel.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 
namespace ChatBox.UI.Windows.UserNamePassword
{
    using System.Windows.Input;

    using ChatBox.UI.Commands;
    using ChatBox.UI.ViewModels;

    /// <summary>
    /// View model for the user name and password window
    /// </summary>
    public class UserNamePasswordViewModel : WindowViewModel
    {
        /// <summary>
        /// The user name entered
        /// </summary>
        private string userName;

        /// <summary>
        /// The masking char for the password, or none
        /// </summary>
        private char passwordChar = '●';

        /// <summary>
        /// Is the password masked at present?
        /// </summary>
        private bool passwordIsShown;

        /// <summary>
        /// Command to save and close
        /// </summary>
        private UserNamePasswordSaveAndCloseCommand saveCommand;

        /// <summary>
        /// Command to close without saving
        /// </summary>
        private WindowCloseCommand closeCommand;

        /// <summary>
        /// Initializes a new instance of the UserNamePasswordViewModel class
        /// </summary>
        /// <param name="saveCommand">the command to save and close</param>
        /// <param name="closeCommand">the command to close</param>
        public UserNamePasswordViewModel(UserNamePasswordSaveAndCloseCommand saveCommand, WindowCloseCommand closeCommand)
        {
            this.saveCommand = saveCommand;
            this.closeCommand = closeCommand;
        }

        /// <summary>
        /// Gets or sets the user name entered
        /// </summary>
        public string UserName
        {
            get
            {
                return this.userName;
            }

            set
            {
                if (this.userName != value)
                {
                    this.userName = value;
                    this.OnPropertyChanged("UserName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the masking char for the password, or none
        /// </summary>
        public char PasswordChar
        {
            get
            {
                return this.passwordChar;
            }

            set
            {
                if (this.passwordChar != value)
                {
                    this.passwordChar = value;
                    this.OnPropertyChanged("PasswordChar");
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the password is shown or masked at present
        /// </summary>
        public bool PasswordIsShown
        {
            get
            {
                return this.passwordIsShown;
            }

            set
            {
                if (this.passwordIsShown != value)
                {
                    this.passwordIsShown = value;
                    this.OnPropertyChanged("PasswordIsShown");

                    this.PasswordChar = this.passwordIsShown ? char.MinValue : '●';
                }
            }
        }

        /// <summary>
        /// Gets the command to close without saving
        /// </summary>
        public ICommand CloseCommand
        {
            get
            {
                return this.closeCommand;
            }
        }

        /// <summary>
        /// Gets the command to save and close
        /// </summary>
        public ICommand SaveCommand
        {
            get
            {
                return this.saveCommand;
            }
        }
    }
}
